package com.sbtr.business.user.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sbtr.business.user.entity.User;
import com.sbtr.business.user.mapper.UserMapper;
import com.sbtr.business.user.service.IUserService;
import com.sbtr.open.user.dto.UserDto;
import com.sbtr.util.BeanCopyUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 用户信息表，仅记录登录过系统的用户信息 服务实现类
 * </p>
 */
@Transactional
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements IUserService {


    @Override
    public UserDto save(UserDto dto) {
        User data = BeanCopyUtils.copyProperties(dto, User.class);
        if (dto.getId() == null) {
            save(data);
            dto.setId(data.getId());
        } else {
            return BeanCopyUtils.copyProperties(data, UserDto.class);
        }
        return dto;
    }

    @Override
    public List<UserDto> search() {

        return baseMapper.getList();
    }

    @Override
    public List<UserDto> searchByuserName(String userName) {
        return baseMapper.getOne(userName);
    }

}
